﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<List<Brjostagjof_H4.Models.Entry>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Brjóstagjöf.is | Greinar
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <!-- TODO: Category headers link to a correct page - VB-->
    <% Brjostagjof_H4.Models.MonsterRepository m = new Brjostagjof_H4.Models.MonsterRepository(); %>
    <% List<Brjostagjof_H4.Models.Category> catList = new List<Brjostagjof_H4.Models.Category>(); %>

    <h3>Yfirlit greina</h3>
    <table id="main-table">
    <div>Flokkar</div>
        <tr>

            <td id="main-table-left">
                <div id="article-cat" class="list-div-style">
                    <% catList = m.getCategories();
                        foreach (var item in catList)
                        { %>
                            <div>
                                <%= Html.ActionLink(item.category_name, "Category", new { id = item.ID })%>
                            </div>
                    <% } %>      
                </div>
            </td>

            <td id="main-table-right">
                <div class="article-preview-container">
                     <% int catCount = 1;
                        List<int> doneCat = new List<int>();
     
                        for (int i = 0; i < Model.Count; i++)
                        {
                
                             if ( !(doneCat.Contains(Model[i].category)) )
                                { 
                                    string tempCat = m.getCategoryName(catCount); %>

                                    <div class="article-preview">
                                        <div class="article-preview-category"> <!-- Make category header action links -->
                                            <%= Html.ActionLink(tempCat, "Category", new { id = m.getCategoryID(tempCat) }) %>
                                        </div>
                                    <div class="article-preview-list">
             
                                        <% foreach (var x in Model) // Make action links to article
                                        {
                                            if (x.category == catCount)
                                            { %>
                                                <%= Html.ActionLink(x.title, "ViewArticle", new { id = x.ID }) %>,
                                            <% }
                                        } %>
             
                                        </div> <!-- preview list ends -->
                                        </div> <!-- container ends -->

                                        <% doneCat.Add(Model[i].category); // Mark this category as "already displayed"
                                        catCount++;
                                        } %>

                        <% } // for ends %>
                </div>
            </td>

        </tr>
    </table>

</asp:Content>
